﻿using HWInfo;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.IO;

namespace HWInfoConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            HardwareInfo hw = new();

            //var kkk = hw.NetworkAdapters;

            //foreach (var item in kkk)
            //{
            //    Console.WriteLine($"name: {item.Name}");
            //    Console.WriteLine($"description: {item.Description}");
            //    Console.WriteLine($"mac_address: {item.MACAddress}");
            //    Console.WriteLine($"ip_count: {item.IPAddressList.Count}");
            //    if (item.IPAddressList.Count > 0)
            //    {
            //        foreach (var ip in item.IPAddressList)
            //        {
            //            Console.WriteLine($"    ip: {ip.AddressFamily} {ip}");
            //        }
            //    }
            //}
            Console.WriteLine("SN: " + hw.GetMachineSN());
            Console.WriteLine(hw.MemoryStatus.ToString());
            Console.WriteLine("CPU温度:" + hw.CpuTemperature);
            Console.WriteLine("CPU使用率:" + hw.CpuUsage);
            Console.WriteLine(ToJson(hw.HDD, true));


            //foreach (var item in hw.NetworkAdapters)
            //{
            //    Console.WriteLine(item.ToString());
            //}

            Console.WriteLine("Hello World!");
        }

        public static string ToJson(object obj, bool indented = false)
        {
            JsonSerializerSettings setting = new()
            {
                Formatting = indented ? Formatting.Indented : Formatting.None,
                StringEscapeHandling = StringEscapeHandling.EscapeNonAscii,
                NullValueHandling = NullValueHandling.Ignore
            };

            setting.Converters.Add(new IsoDateTimeConverter()
            {
                DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
            });

            return JsonConvert.SerializeObject(obj, setting);
        }
    }
}
